set more off

cd c:\data\constituency-size

use data\cs-recode.dta, clear
replace salary_real_nomiss= salary_real_nomiss/1000
collapse cshouse salary_real_nomiss expend_adj_nomiss ///
	t_slength_nomiss sqindex1_nomiss, by(year fips)

foreach var in salary_real expend_adj t_slength sqindex1 {
		rename `var'_nomiss `var'_actual
		}
	
gen pipe="|"
gen constant=-.4
rename cshouse csactual

gen data=1

append using data\cs-sim.dta

local options1= "sort lcolor(black) lwidth(medthick)"
local options2= "sort lcolor(black) lpattern(dash) lwidth(thin)"
local general= "legend(off) scheme(s1mono) plotregion(lcolor(none))"

local title_salary_real="Salary"
local title_sqindex1="Index"
local title_expend_adj="Expenditures"
local title_t_slength="Session Length"


foreach prof in salary_real expend_adj t_slength sqindex1 {

twoway line fd cshouse if `prof'_nomiss~=. &marg_prof==1, `options1'  ///
		|| line fd_hi cshouse if `prof'_nomiss~=. &marg_prof==1, `options2' ///
		|| line fd_lo cshouse if `prof'_nomiss~=. &marg_prof==1, `options2' ///
			title(`title_`prof'', size(medlarge)) `general' ///
			ylabel(-.4(.2).6) yline(0, lcolor(gs8) lwidth(thin)) ///
		|| scatter constant csactual, msymbol(none) mlabel(pipe) ///
			mlabsize(tiny) mlabposition(c) mlcolor(gs8) ///
			saving(marg-cs-`prof'.gph, replace)

			
graph export marg-cs-`prof'.eps, replace
}
graph combine marg-cs-sqindex1.gph marg-cs-expend_adj.gph marg-cs-salary_real.gph marg-cs-t_slength.gph ///
	, row(2) xsize(5) ysize(5) ycommon xcommon altshrink ///
	b1title(Constituency Size (in tens of thousands)) l1title(Difference in Pr(y>2))

graph export marg-prof.eps, replace	

replace constant=-.2

local salary_real_options= "xlabel(0(20)120)"
local expend_adj_options= " "
local t_slength_options= " "
local sqindex1_options= " "

replace salary_real_nomiss= salary_real_nomiss/1000
	
foreach prof in salary_real expend_adj t_slength sqindex1 {

twoway line fd `prof'_nomiss if `prof'_nomiss~=. &marg_prof==., `options1'  ///
		|| line fd_hi `prof'_nomiss if `prof'_nomiss~=. &marg_prof==., `options2' ///
		|| line fd_lo `prof'_nomiss if `prof'_nomiss~=. &marg_prof==., `options2' ///
			xtitle(`title_`prof'', size(med)) `general' ///
			ylabel(-.2(.05).1) ``prof'_options' yline(0, lcolor(gs8) lwidth(thin)) ///
		|| scatter constant `prof'_actual, msymbol(none) mlabel(pipe) ///
			mlabsize(tiny) mlabposition(c) mlcolor(gs8) ///
			saving(marg-`prof'-cs.gph, replace)

			
graph export marg-`prof'-cs.eps, replace
}
graph combine marg-sqindex1-cs.gph marg-expend_adj-cs.gph marg-salary_real-cs.gph marg-t_slength-cs.gph ///
	, row(2) xsize(5) ysize(5) ycommon  altshrink ///
	b1title(Professionalism) l1title(Difference in Pr(y>2))	
	
graph export marg-cs.eps, replace

scatter cs_house x, connect(L) xlabel(none) xtitle("")msymbol(none) lwidth(vvthin) lcolor(gs3) xsc(r(.5 2.5)) ysize(9) xsize(3) plotregion(lcolor(none)) graphregion(lcolor(none)) || scatter cs_house x2 if x==1, mlabel(stateabv) mlabsize(tiny) mlabcolor(black) msymbol(none) mlabposition(0) || scatter cs_house x2 if x==2, mlabel(stateabv) mlabsize(tiny) mlabcolor(black) msymbol(none) mlabposition(0) legend(off) xsc(off) ysc(off)
